#include "bsp_spi.h"



extern SPI_HandleTypeDef hspi2,hspi1;



void BMI008_AcceleraterCS(uint8_t enable)
{
	if( enable )
		HAL_GPIO_WritePin(SPI2_CS1_GPIO_Port,SPI2_CS1_Pin,GPIO_PIN_RESET);
	else
		HAL_GPIO_WritePin(SPI2_CS1_GPIO_Port,SPI2_CS1_Pin,GPIO_PIN_SET);
}



void BMI008_GyroCS(uint8_t enable)
{
	if( enable )
		HAL_GPIO_WritePin(SPI2_CS2_GPIO_Port,SPI2_CS2_Pin,GPIO_PIN_RESET);
	else
		HAL_GPIO_WritePin(SPI2_CS2_GPIO_Port,SPI2_CS2_Pin,GPIO_PIN_SET);
}



uint8_t BMI008_Write(uint8_t *data,uint16_t length)
{
	return HAL_SPI_Transmit( &hspi2,data,length,100);
}


uint8_t BMI008_Read(uint8_t *data,uint16_t length)
{
	return HAL_SPI_Receive( &hspi2,data,length,100);
}




void AK09915_CS(uint8_t enable)
{
	if( enable )
		HAL_GPIO_WritePin(SPI2_CS_GPIO_Port,SPI2_CS_Pin,GPIO_PIN_RESET);
	else
		HAL_GPIO_WritePin(SPI2_CS_GPIO_Port,SPI2_CS_Pin,GPIO_PIN_SET);
}

uint8_t AK09915_Write(uint8_t *data,uint16_t length)
{
	return HAL_SPI_Transmit( &hspi2,data,length,100);
}

uint8_t AK09915_Read(uint8_t *data,uint16_t length)
{
	return HAL_SPI_Receive( &hspi2,data,length,100);
}





//SPL06:气压计
void SPL06_CS(uint8_t enable)
{
	if( enable )
		HAL_GPIO_WritePin(SPI2_CS3_GPIO_Port,SPI2_CS3_Pin,GPIO_PIN_RESET);
	else
		HAL_GPIO_WritePin(SPI2_CS3_GPIO_Port,SPI2_CS3_Pin,GPIO_PIN_SET);
}

//д����
uint8_t SPL06_Write(uint8_t *data,uint16_t length)
{
	return HAL_SPI_Transmit( &hspi2,data,length,100);
}
//������
uint8_t SPL06_Read(uint8_t *data,uint16_t length)
{
	return HAL_SPI_Receive( &hspi2,data,length,100);
}


//Flash:W25Q32
//CS片选：
void W25Q32_CS(uint8_t enable)
{
	if( enable )
		HAL_GPIO_WritePin(SPI1_CS_GPIO_Port,SPI1_CS_Pin,GPIO_PIN_RESET);
	else
		HAL_GPIO_WritePin(SPI1_CS_GPIO_Port,SPI1_CS_Pin,GPIO_PIN_SET);
}

//读：


uint8_t W25Q32_SendReadByte ( uint8_t send_byte )
{
	uint8_t ret=0;		//返回结果
	HAL_SPI_TransmitReceive( &hspi1,&send_byte,&ret,1,10);
	return ret;
}


uint8_t W25Q32_SendBuffer(uint8_t *buf,uint8_t size)
{
	uint8_t ret=0;		//返回结果
	ret = HAL_SPI_Transmit(&hspi1,buf,size,1000);
	return ret;	
	
}
uint8_t W25Q32_RecvBuffer(uint8_t *buf,uint8_t size)
{
	uint8_t ret=0;		//返回结果
	ret = HAL_SPI_Receive(&hspi1,buf,size,1000);
	return ret;		
}
